package com.demo.common;


import com.alibaba.fastjson.annotation.JSONField;
import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableLogic;
import com.baomidou.mybatisplus.annotation.Version;
import com.baomidou.mybatisplus.extension.activerecord.Model;
import com.fasterxml.jackson.annotation.JsonIgnore;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;

import java.time.LocalDateTime;

/**
 * 实体基础类
 *
 * @param <T>
 * @author leo
 */
@Data
public class BasicEntity<T extends Model> extends Model<BasicEntity<T>> {


    /**
     * 主键
     */
    @ApiModelProperty(hidden = true)
    @JsonIgnore
    @TableId(value = "id", type = IdType.AUTO)
    private Long id;

    @ApiModelProperty(hidden = true)
    @TableLogic
    @TableField(value = "is_deleted")
    private Integer deleted;

    /**
     * 创建人
     */
    @ApiModelProperty(hidden = true)
    @TableField(value = "created_id")
    private String createdId;
    @ApiModelProperty(hidden = true)
    @TableField(value = "created_name")
    private String createdName;
    /**
     * 修改人
     */
    @ApiModelProperty(hidden = true)
    @TableField(value = "modified_id")
    private String modifiedId;
    @ApiModelProperty(hidden = true)
    @TableField(value = "modified_name")
    private String modifiedName;
    /**
     * 创建时间
     * 自动填充
     */
    @ApiModelProperty(hidden = true)
    @TableField(value = "created_time", fill = FieldFill.INSERT)
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @JSONField(format = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime createdTime;

    /**
     * 修改时间
     * 自动填充
     */
    @ApiModelProperty(hidden = true)
    @Version
    @TableField(value = "modified_time", fill = FieldFill.INSERT_UPDATE)
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @JSONField(format = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime modifiedTime;

}
